//
//  PendApprovalShowPassFormViewController.m
//  ZJControlsClass
//
//  Created by mac on 2024/12/10.
//

#import "PendApprovalShowPassFormViewController.h"
#import "ZJPendApprovallNetWorking.h"


#import "HomeAddGoodsTableViewCell.h"
#import "ZJPublicFormAreatTableViewCell.h"
#import "ZJPublicFormTableViewCell.h"
#import "ZJPublicUploadPhotoTableViewCell.h"
#import "HomeNetWorking.h"
#import "HomeUnitModel.h"
#import "TZImagePickerController.h"
#import "HomeGetDetailAllModel.h"
#import "HomeMySlipleModel.h"
#import "ZJPendApprovalDictModel.h"


// 弹出框
#import "SaTMNewUIPickerAlertView.h"
#import "SexAlertView.h"
#import "AreaAlertView.h"
#import "HomePersonAlertView.h"
#import "JWAddressPickerView.h" // 地址选择器
#import "StarTimeAlertView.h"
#import "AlertControllAlertView.h"



@interface PendApprovalShowPassFormViewController ()<UITableViewDelegate,UITableViewDataSource,TZImagePickerControllerDelegate,UITextFieldDelegate,UIDocumentPickerDelegate>{
    NSInteger goodsHei;
}

@property (nonatomic,strong) UILabel * titleLabel;
@property (nonatomic,strong) UITableView * tableView;
@property (nonatomic,strong) NSMutableArray * dataSource;
@property (nonatomic,strong) NSMutableArray * photoArr;
@property (nonatomic,strong) UIView * bottomView;
@property (nonatomic,strong) UIButton * canleBtn;
@property (nonatomic,strong) UIButton * uploadBtn;

@property (nonatomic,strong) HomeNetWorking * manager;
@property (nonatomic,strong) HomeGetDetailAllNetworking * allManager;
@property (nonatomic,strong) NSMutableArray * allDataSource;

@property (nonatomic,strong) HomeProcessStarNetworking * uploadManager;
@property (nonatomic,strong) HomeUploadFileNetWorking * fileUploadManager;
@property (nonatomic,strong) NSMutableArray * chooseImgArr;

@property (nonatomic,strong) HomeListMySimpleNetworking * simpleManager;
@property (nonatomic,strong) HomeMySlipleModel * simpleModel;



@property (nonatomic,strong) SaTMNewUIPickerAlertView * checkPickerView;
@property (nonatomic,strong) SexAlertView * sexView;
@property (nonatomic,strong) AreaAlertView * areaAlertView;
@property (nonatomic,strong) HomePersonAlertView * personAlertView;
@property (nonatomic,strong) StarTimeAlertView * startTimeAlertView;

@property (nonatomic,strong) HomeListAllSimpleNetWorking * AllSimplemanager;
@property (nonatomic,strong) NSMutableArray * allSimpleArr;

@property (nonatomic,strong) HomeDictDataTypeNetWorking * DictManager;
@property (nonatomic,strong) NSMutableArray * DictArr;
@property (nonatomic,strong) AlertControllAlertView * controllAlertView;
@property (nonatomic,strong) NSString * controllStr;

@property (nonatomic,strong) ZJPendApprovallInfoAgreeNetWorking *uploadImgManager;


@property (nonatomic,copy) NSString * processDefinitionId;
@property (nonatomic,strong) UITextView *inputTextView;
// 整合数据
@property (nonatomic,strong) NSMutableArray * AreaUpData;
@property (nonatomic,strong) NSMutableArray * personUpData;








@end

@implementation PendApprovalShowPassFormViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    
    goodsHei = ALIGN_HEIGHT_PT(180);
    
    [self setUpUI];
    [self getDetailAllNet];
    [self getListMySimpleNet];
    [self getAllSimpleNetWorking];
    [self getDictNet];
}


-(void)setUpUI{
    
    [self.view addSubview:self.titleLabel];
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomView];
    [self.bottomView addSubview:self.canleBtn];
    [self.bottomView addSubview:self.uploadBtn];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.view);
        make.height.equalTo(@(StatusBarHeight));
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view).with.offset(-ALIGN_HEIGHT_PT(100));
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.view);
        make.height.equalTo(@(ALIGN_HEIGHT_PT(100)));
    }];
    
    [self.canleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bottomView).with.offset(ALIGN_WIDTH_PT(10));
        make.top.equalTo(self.bottomView).with.offset(ALIGN_HEIGHT_PT(20));
        make.size.equalTo(@(CGSizeMake((SCREEN_WIDTH - 30) / 2, ALIGN_HEIGHT_PT(45))));
    }];
    
    [self.uploadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.bottomView).with.offset(-ALIGN_WIDTH_PT(10));
        make.centerY.equalTo(self.canleBtn.mas_centerY);
        make.size.equalTo(@(CGSizeMake((SCREEN_WIDTH - 30) / 2, ALIGN_HEIGHT_PT(45))));
    }];
    
    
}

-(void)setFormItems:(NSString *)formItems{
    
    NSData *jsonData = [formItems dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error;
    NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
    NSLog(@"=====-----%@",array);
    if (error) {
        NSLog(@"JSON解析出错：%@", error);
        [LUtilityTools showAlertWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"JSON解析出错：%@", error] buttonAction:^{
            
        }];
        
        return;
    }

    [self.dataSource addObjectsFromArray:[HomeUnitModel mj_objectArrayWithKeyValuesArray:array]];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [self.dataSource enumerateObjectsUsingBlock:^(HomeUnitModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.name isEqualToString:@"currentUserName"]){
            obj.props.input = [defaults valueForKey:@"nickname"];
            obj.props.placeholder = [defaults valueForKey:@"nickname"];
        }
    }];
    
    [self.tableView reloadData];

    
    
}


-(void)getDictNet{
    
    [self.DictManager dispatchTaskWithParam:@{@"type":@"access_control"} completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if (responseObject && [responseObject[@"code"] intValue] == 200){
            self.DictArr = [NSMutableArray arrayWithArray:[ZJPendApprovalDictModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]]];
        }else{
            [LUtilityTools showAlertWithTitle:@"温馨提示" message:responseObject[@"msg"] buttonAction:^{
                
            }];
        }
    }];
    
    
    
}


-(void)getDetailAllNet{
    
    [self.allManager dispatchTaskWithParam:@{} completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if (responseObject && [responseObject[@"code"] intValue] == 200){
            
            [self.allDataSource addObjectsFromArray:[HomeGetDetailAllModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]]];
            [self.tableView reloadData];
            
        }else{
            [LUtilityTools showAlertWithTitle:@"温馨提示" message:responseObject[@"msg"] buttonAction:^{
                
            }];
        }
    }];
    
}

-(void)getListMySimpleNet{ // 获取我的公司下部门精简信息列表
    
    [self.simpleManager dispatchTaskWithParam:@{} completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if (responseObject && [responseObject[@"code"] intValue] == 200){
           
            self.simpleModel = [HomeMySlipleModel mj_objectWithKeyValues:responseObject[@"data"]];
       
        }else{
            [LUtilityTools showAlertWithTitle:@"温馨提示" message:responseObject[@"msg"] buttonAction:^{
                
            }];
        }
    }];
    
}



-(void)getAllSimpleNetWorking{
    
    [self.AllSimplemanager dispatchTaskWithParam:@{} completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if (responseObject && [responseObject[@"code"] intValue] == 200){
            self.allSimpleArr = [NSMutableArray arrayWithArray:responseObject[@"data"]];
        }else{
            [LUtilityTools showAlertWithTitle:@"温馨提示" message:responseObject[@"msg"] buttonAction:^{
                
            }];
        }
    }];
}





#pragma mark -- 点击事件

-(void)respondsTo_canleBtn{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
 
// 提交
-(void)respondsTo_uploadBtn{
    
    // 整合数据
    NSMutableDictionary * paramer = @{}.mutableCopy;
    [self.dataSource enumerateObjectsUsingBlock:^(HomeUnitModel  * obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        
        if ([obj.valueType isEqualToString:@"Select"]){ // 判断
            // 通讯区域
            if ([obj.name isEqualToString:@"common_apply_pass_region"]){

                [paramer setValue:[SStringUtils jsonStringWithParameters:self.AreaUpData] forKey:[NSString stringWithFormat:@"%@|%@",obj.name,obj.id]];
            }
            // 选择员工
            if ([obj.name isEqualToString:@"common_user_id"]){
                [paramer setValue:[SStringUtils jsonStringWithParameters:self.personUpData] forKey:[NSString stringWithFormat:@"%@|%@",obj.name,obj.id]];
            }
            
            // 选择部门
            if ([obj.name isEqualToString:@"common_department_id"]){
                NSDictionary * dic = @{@"id":obj.id,
                                       @"name":obj.props.input
                };
                [paramer setValue:[SStringUtils jsonStringWithParameters:dic] forKey:[NSString stringWithFormat:@"%@|%@",obj.name,obj.id]];

            }
            
            
        }else{
            
            if ([obj.valueType isEqualToString:@"DateRange"] || [obj.valueType isEqualToString:@"TimeRange"]){ // 开始时间  结束时间
                
                NSArray * arr = @[obj.props.starTime,obj.props.endTime];
                [paramer setValue:arr forKey:[NSString stringWithFormat:@"%@|%@",obj.name,obj.id]];
                
            }else{
                [paramer setValue:obj.props.input forKey:[NSString stringWithFormat:@"%@|%@",obj.name,obj.id]];
            }
            
        }
        
        if ([obj.valueType isEqualToString:@"Image"] && obj.props.url){
            
            NSMutableArray * arr = @[].mutableCopy;
            NSDictionary * dic  = @{@"url":[NSString stringWithFormat:@"%@",obj.props.url?obj.props.url:@""],
                                    @"name":[NSString stringWithFormat:@"%@",obj.props.filename?obj.props.filename:@""]
            };
            [arr addObject:dic];
            
            [paramer setValue:[SStringUtils jsonStringWithParameters:arr] forKey:[NSString stringWithFormat:@"%@|%@",obj.name,obj.id]];
        }
        
        if ([obj.name isEqualToString:@"access_control"]){ // 通行门禁
            [paramer setValue:self.controllStr forKey:[NSString stringWithFormat:@"%@|%@",obj.name,obj.id]];
        }
        
    }];

    
    NSMutableDictionary * dic = @{}.mutableCopy;
    [dic setValue:paramer forKey:@"formData"];
    [dic setValue:self.processDefinitionId forKey:@"processDefinitionId"];
    [dic setValue:self.taskId forKey:@"taskId"];
    [dic setValue:self.inputTextView.text forKey:@"comments"];
    

    [self.uploadImgManager dispatchTaskWithParam:dic completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if (responseObject && [responseObject[@"code"] intValue] == 200){
        
            [MBProgressHUD showSuccess:@"通过成功"];
            [self dismissViewControllerAnimated:YES completion:^{
//                // 获取当前导航控制器
//                UINavigationController *nav = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
//                // 遍历导航控制器的视图控制器栈
//                for (UIViewController *controller in nav.viewControllers) {
//                    if ([controller isKindOfClass:NSClassFromString(@"ApprovaledViewController")]) {
//                        [nav popToViewController:controller animated:YES];
//                        break;
//                    }
//                }
            }];
            
        }else{
            [LUtilityTools showAlertWithTitle:@"温馨提示" message:responseObject[@"msg"] buttonAction:nil];
        }
        
    }];
    
    
    
   
    
    
    
}


#pragma mark -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HomeUnitModel * model = self.dataSource[indexPath.row];
    if (![model.valueType isEqualToString:@"Image"] && ![model.name isEqualToString:@"common_apply_pass_region"] && ![model.name isEqualToString:@"tool_pass_region"] && ![model.name isEqualToString:@"tool_table"]) {

        
                
            ZJPublicFormTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ZJPublicFormTableViewCell"];
            if (!cell) {
                cell = [[ZJPublicFormTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"ZJPublicFormTableViewCell"];
            }

            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = model;

            return cell;
        
        

    }else if ([model.name isEqualToString:@"common_apply_pass_region"] || [model.name isEqualToString:@"tool_pass_region"]){ // 通行区域
        ZJPublicFormAreatTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ZJPublicFormAreatTableViewCell"];
        if (!cell){
            cell = [[ZJPublicFormAreatTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"ZJPublicFormAreatTableViewCell"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.model = model;
        
        return cell;
        
    }else if ([model.name isEqualToString:@"tool_table"]){ // 货物
        HomeAddGoodsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeAddGoodsTableViewCell"];
        if (!cell){
            cell = [[HomeAddGoodsTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"HomeAddGoodsTableViewCell"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.model = model;

        cell.block = ^(NSInteger hei) {
            self->goodsHei = hei;
            // 使用主线程刷新表格
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableView beginUpdates];
                [self.tableView endUpdates];

            });
        };

        
        return cell;
        
  
    }else{
            
            ZJPublicUploadPhotoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ZJPublicUploadPhotoTableViewCell"];
            if (!cell) {
                cell = [[ZJPublicUploadPhotoTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"ZJPublicUploadPhotoTableViewCell"];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            cell.titleLabel.text = model.props.title;
            cell.uploadLabel.text = model.props.placeholder;
            
            return cell;
            
        }
        
    
    return [UITableViewCell new];
    
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HomeUnitModel * model = self.dataSource[indexPath.row];
    if (![model.valueType isEqualToString:@"Image"]) {
        
        ZJPublicFormTableViewCell * cell = (ZJPublicFormTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
        
      
        if ([model.name isEqualToString:@"personal_sex"]) { // 选择男女
            
            __weak typeof (self)weakSelf = self;
            weakSelf.sexView = [SexAlertView new];
            weakSelf.sexView.dataSource = [NSMutableArray arrayWithObjects:@"男",@"女", nil];
            weakSelf.sexView.block = ^(NSString * sexStr) {
                
                model.props.input = sexStr;
                cell.inputTextF.text = sexStr;
                
            };
            
            [kWindow addSubview:self.sexView];
            
        }else if ([model.valueType isEqualToString:@"DateRange"] || [model.valueType isEqualToString:@"TimeRange"]){ // 包含开始时间  结束时间
            
            __weak typeof (self)weakSelf  = self;
            weakSelf.startTimeAlertView = [StarTimeAlertView new];
            weakSelf.startTimeAlertView.StartBlock = ^(NSString * star, NSString * end) {
                if (star) {
                    model.props.starTime = star;
                    model.props.endTime = end;
                    cell.inputTextF.text = [NSString stringWithFormat:@"%@-%@",star,end];
                }
            };
            [kWindow addSubview:weakSelf.startTimeAlertView];
            
        }else if ([model.valueType isEqualToString:@"Date"] || [model.valueType isEqualToString:@"DateTime"] ){ // 出生年月日 || 行截止日期
            
            __weak typeof(self)weakSelf = self;
            weakSelf.checkPickerView = [[SaTMNewUIPickerAlertView alloc]init];
            weakSelf.checkPickerView.block = ^(NSString * timeStr) {
                if (timeStr) {
                    model.props.input = timeStr;
                    cell.inputTextF.text = timeStr;
                }
            };
            [kWindow addSubview:self.checkPickerView];
            
        }else if ([model.name isEqualToString:@"personal_origin"]){ // 选择籍贯
            
            [JWAddressPickerView showWithAddressBlock:^(NSString *province, NSString *city, NSString *area) {
                NSString * addressStr = [NSString stringWithFormat:@"%@-%@-%@",province,city,area];
                model.props.input = addressStr;
                cell.inputTextF.text = addressStr;
            }];
            
            
            
        }else if ([model.name isEqualToString:@"common_apply_pass_region"] || [model.name isEqualToString:@"tool_pass_region"]){
            
                    __weak typeof (self)weakSelf = self;
                    weakSelf.areaAlertView = [AreaAlertView new];
                    weakSelf.areaAlertView.dataSource = [NSMutableArray arrayWithArray:self.allDataSource];
                    weakSelf.areaAlertView.Areablock = ^(NSMutableArray * upArr, NSMutableArray * showArr) {
                        
                        self.AreaUpData = [NSMutableArray arrayWithArray:upArr];
                        NSString * str = [showArr  componentsJoinedByString:@","];
                        model.props.input = str;
                        if (upArr.count > 0){
                            model.props.placeholder = @"";
                        }else{
                            model.props.placeholder = @"请选择区域";
                        }
                        
                        [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:NO];
                    };
                    
                    [kWindow addSubview:self.areaAlertView];
                    
        }else if ([model.name isEqualToString:@"common_user_id"]){ // 选择员工
            
            __weak typeof (self) weakSelf = self;
            weakSelf.personAlertView = [HomePersonAlertView new];
            weakSelf.personAlertView.model = self.simpleModel;
            weakSelf.personAlertView.personBlock = ^(NSMutableArray * upArr, NSMutableArray * showArr) {
                
                self.personUpData = [NSMutableArray arrayWithArray:upArr];
                NSString * str = [showArr componentsJoinedByString:@"-"];
                model.props.input = str;
                cell.inputTextF.text = str;
            };
            
            
            
            [kWindow addSubview:self.personAlertView];
            
        }else if ([model.name isEqualToString:@"common_department_id"]){ // 选择部门
            
            __weak typeof (self)weakSelf = self;
            weakSelf.sexView = [SexAlertView new];
            weakSelf.sexView.TypeBool = YES;
            weakSelf.sexView.dataSource = [NSMutableArray arrayWithArray:self.simpleModel.orgList];
            weakSelf.sexView.block = ^(NSString * sexStr) {
                
                model.props.input = sexStr;
                cell.inputTextF.text = sexStr;
                
            };
            [kWindow addSubview:self.sexView];

            
        }else if ([model.name isEqualToString:@"background_review_result"]){ // 背景审查结果
            
            __weak typeof (self)weakSelf = self;
            weakSelf.sexView = [SexAlertView new];
            weakSelf.sexView.dataSource = [NSMutableArray arrayWithObjects:@"审核通过",@"审核不通过", nil];
            weakSelf.sexView.block = ^(NSString * sexStr) {
                
                model.props.input = sexStr;
                cell.inputTextF.text = sexStr;
                
            };
            
            [kWindow addSubview:self.sexView];

            
        }else if ([model.name isEqualToString:@"common_file"]){ // 文件上传
            // 创建文档选择器实例
            NSArray *documentTypes = @[@"public.content", @"public.text", @"public.source-code", @"public.image", @"public.audiovisual-content", @"public.movie", @"public.audio", @"public.zip-archive", @"com.pkware.zip-archive", @"public.composite-content", @"public.text"];
            
            UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeImport];
            documentPicker.delegate = self;
            documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
            [self presentViewController:documentPicker animated:YES completion:nil];
            
            
        }else if ([model.name isEqualToString:@"personal_leading_people"]){ // 引领人
            
            __weak typeof (self)weakSelf = self;
            weakSelf.sexView = [SexAlertView new];
            
            NSMutableArray * simArr = @[].mutableCopy;
            [self.allSimpleArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [simArr addObject:obj[@"nickname"]];
            }];
            weakSelf.sexView.dataSource = [NSMutableArray arrayWithArray:simArr];
            weakSelf.sexView.block = ^(NSString * sexStr) {
                
                model.props.input = sexStr;
                cell.inputTextF.text = sexStr;
                
            };
            
            [kWindow addSubview:self.sexView];
            
            
        }else if ([model.name isEqualToString:@"access_control"]){ // 通行门禁
            __weak typeof (self)weakSelf = self;
            weakSelf.controllAlertView = [AlertControllAlertView new];
            weakSelf.controllAlertView.dataSource = [NSMutableArray arrayWithArray:self.DictArr];
            weakSelf.controllAlertView.block = ^(NSString * str) {
                cell.inputTextF.text = str;
                self.controllStr = str;
            };
            [kWindow addSubview:weakSelf.controllAlertView];
            
        }
    
    }else{ // 选择照片
        
        ZJPublicUploadPhotoTableViewCell * cell = (ZJPublicUploadPhotoTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
        
        TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc]initWithMaxImagesCount:9 columnNumber:4 delegate:self pushPhotoPickerVc:YES];
        //设置目前已经选中的图片数组
        imagePickerVc.allowPickingVideo = NO;
        imagePickerVc.allowTakeVideo = NO;
        imagePickerVc.showSelectedIndex = YES;

        [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            
            self.photoArr = @[].mutableCopy;
            
            
            [self.photoArr addObjectsFromArray:photos];
            NSString * str = [NSString stringWithFormat:@"%@",[self.photoArr firstObject]];
            if ([str hasPrefix:@"http://"] || [str hasPrefix:@"https://"]) {
                [cell.photoImg sd_setImageWithURL:[NSURL URLWithString:str]];
            }else{
                cell.photoImg.image = [self.photoArr firstObject];
            }
            cell.addImg.hidden = YES;
            cell.uploadLabel.hidden = YES;
            
            NSString * filename = [assets valueForKey:@"filename"];
            
            // 单张图片上传
            [self.fileUploadManager uploadImageWithParam:@{@"filename":filename} sourceImg:[self.photoArr firstObject] completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
                if (responseObject && [responseObject[@"code"] intValue] == 200){
                    
                    NSString * str = [SStringUtils jsonStringWithParameters:responseObject[@"data"]];
                    NSData * dicData = [str dataUsingEncoding:NSUTF8StringEncoding];
                    NSError * dicErr ;
                    NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:dicData options:NSJSONReadingMutableContainers error:&dicErr];
                    model.props.url = dic[@"url"];
                    model.props.filename = dic[@"name"];
                }
            }];
            
        }];
        imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
        [[SaViewControllerUtils currentViewController] presentViewController:imagePickerVc animated:YES completion:nil];
    
    }
    
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ALIGN_HEIGHT_PT(165))];
    
    self.inputTextView = [[UITextView alloc] init];
    self.inputTextView.frame = CGRectMake(ALIGN_WIDTH_PT(15), 10, SCREEN_WIDTH - ALIGN_WIDTH_PT(30), ALIGN_HEIGHT_PT(145));
    self.inputTextView.font = FONT14;
    self.inputTextView.backgroundColor = COLOR_RGB(244, 244, 244);
    self.inputTextView.layer.cornerRadius = 10;
    self.inputTextView.layer.masksToBounds = YES;
    self.inputTextView.textColor = [UIColor blackColor];
    
    // 设置placeholder
    UILabel *placeholderLabel = [[UILabel alloc] init];
    placeholderLabel.text = @"请输入审批意见";
    placeholderLabel.font = FONT14;
    placeholderLabel.textColor = [UIColor grayColor];
    placeholderLabel.frame = CGRectMake(5, 8, 200, 20);
    [self.inputTextView addSubview:placeholderLabel];
    
    // 监听输入,隐藏placeholder
    [[NSNotificationCenter defaultCenter] addObserverForName:UITextViewTextDidChangeNotification object:self.inputTextView queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
        placeholderLabel.hidden = self.inputTextView.text.length > 0;
    }];
    
    [footerView addSubview:self.inputTextView];
    
    return footerView;
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return ALIGN_HEIGHT_PT(165);
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.0001;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * view = [UIView new];
    return view;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    HomeUnitModel * model = self.dataSource[indexPath.row];
    if ([model.valueType isEqualToString:@"Image"]) {
        return ALIGN_HEIGHT_PT(145);
    }else if ([model.name isEqualToString:@"tool_table"]){
        return MAX(goodsHei, ALIGN_HEIGHT_PT(180));
    }else{
        if ([model.name isEqualToString:@"common_apply_pass_region"] || [model.name isEqualToString:@"tool_pass_region"]){
            return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[ZJPublicFormAreatTableViewCell class] contentViewWidth:SCREEN_WIDTH / 2 - ALIGN_WIDTH_PT(30)];
        }else{
            return ALIGN_HEIGHT_PT(50);
        }
    }
    return 0;
}

#pragma mark -- UIDocumentPickerDelegate
-(void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url{
    // 获取文件名
    NSString *filename = [url lastPathComponent];
    
    // 读取文件数据
    NSData *fileData = [NSData dataWithContentsOfURL:url];
    
    [self.fileUploadManager uploadImageWithParam:@{@"filename":filename} sourceImg:[UIImage imageWithData:fileData] completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if (responseObject && [responseObject[@"code"] intValue] == 200){
            // 解析返回数据
            NSString *str = [SStringUtils jsonStringWithParameters:responseObject[@"data"]];
            NSData *dicData = [str dataUsingEncoding:NSUTF8StringEncoding];
            NSError *dicErr;
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:dicData
                                                              options:NSJSONReadingMutableContainers
                                                                error:&dicErr];

            // 更新模型数据
//            HomeUnitModel *model = [self.dataSource lastObject];
//            model.props.url = dic[@"url"];
//            model.props.filename = dic[@"name"];
//
//            // 刷新UI
//            [self.tableView reloadData];
        }
    }];

}

- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
    // 用户取消选择时的处理逻辑
    NSLog(@"取消选择文件");
}



#pragma mark -- 懒加载

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:15 weight:0.3];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.text = @"业务审批";
    }
    return _titleLabel;
}

-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:(UITableViewStyleGrouped)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}
-(UIView *)bottomView{
    if (!_bottomView) {
        _bottomView = [UIView new];
        _bottomView.backgroundColor = [UIColor whiteColor];
    }
    return _bottomView;
}

-(UIButton *)canleBtn{
    if (!_canleBtn) {
        _canleBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_canleBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_canleBtn setTitleColor:COLOR_RGB(50, 113, 237) forState:UIControlStateNormal];
        _canleBtn.titleLabel.font = FONT16;
        _canleBtn.layer.cornerRadius = 10;
        _canleBtn.layer.masksToBounds = YES;
        _canleBtn.layer.borderColor = COLOR_RGB(50, 113, 237).CGColor;
        _canleBtn.layer.borderWidth = 0.5;
        [_canleBtn addTarget:self action:@selector(respondsTo_canleBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _canleBtn;
}

-(UIButton *)uploadBtn{
    if (!_uploadBtn) {
        _uploadBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_uploadBtn setTitle:@"确认通过" forState:UIControlStateNormal];
        [_uploadBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _uploadBtn.backgroundColor = COLOR_RGB(50, 113, 237);
        _uploadBtn.titleLabel.font = FONT16;
        _uploadBtn.layer.cornerRadius = 10;
        _uploadBtn.layer.masksToBounds = YES;
        [_uploadBtn addTarget:self action:@selector(respondsTo_uploadBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _uploadBtn;
}


-(HomeNetWorking *)manager{
    if (!_manager) {
        _manager = [HomeNetWorking new];
    }
    return _manager;
}
-(HomeGetDetailAllNetworking *)allManager{
    if (!_allManager){
        _allManager = [HomeGetDetailAllNetworking new];
    }
    return _allManager;
}


-(HomeProcessStarNetworking *)uploadManager{
    if (!_uploadManager){
        _uploadManager = [HomeProcessStarNetworking new];
    }
    return _uploadManager;
}

-(HomeUploadFileNetWorking *)fileUploadManager{
    if (!_fileUploadManager){
        _fileUploadManager = [HomeUploadFileNetWorking new];
    }
    return _fileUploadManager;
}

-(HomeListMySimpleNetworking *)simpleManager{
    if (!_simpleManager){
        _simpleManager = [HomeListMySimpleNetworking new];
    }
    return _simpleManager;
}


-(HomeListAllSimpleNetWorking *)AllSimplemanager{
    if (!_AllSimplemanager){
        _AllSimplemanager = [HomeListAllSimpleNetWorking new];
    }
    return _AllSimplemanager;
}

-(ZJPendApprovallInfoAgreeNetWorking *)uploadImgManager{
    if (!_uploadImgManager){
        _uploadImgManager = [ZJPendApprovallInfoAgreeNetWorking new];
    }
    return _uploadImgManager;
}



-(NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}
-(NSMutableArray *)allDataSource{
    if (!_allDataSource){
        _allDataSource = [NSMutableArray array];
    }
    return _allDataSource;
}

-(HomeDictDataTypeNetWorking *)DictManager{
    if (!_DictManager){
        _DictManager = [HomeDictDataTypeNetWorking new];
    }
    return _DictManager;
}


@end
